package com.houger.ddd.seckill.template;

import com.houger.ddd.common.utils.BusinessException;
import com.houger.ddd.common.utils.DateUtils;
import com.houger.ddd.common.utils.StatusCode;
import com.houger.ddd.seckill.constant.InstanceStatusEnum;
import com.houger.ddd.seckill.constant.PlatformEnum;
import com.houger.ddd.seckill.constant.TemplateStatusEnum;
import com.houger.ddd.seckill.facade.dto.ActivityInstanceDto;
import com.houger.ddd.seckill.template.context.ActivityContext;
import com.houger.ddd.seckill.template.holder.BeanHolder;
import com.houger.ddd.seckill.template.annotation.ActivityTemplateConfig;
import com.houger.ddd.seckill.facade.dto.ext.SeckillBizExtDataDto;
import com.houger.ddd.seckill.facade.dto.ext.SeckillInstanceExtDataDto;
import com.houger.ddd.seckill.facade.dto.ext.SeckillRewardItemExtDataDto;
import com.houger.ddd.seckill.facade.dto.ext.SeckillUiExtDataDto;
import com.houger.ddd.seckill.infra.entity.ActivityInstance;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.List;

import static com.houger.ddd.common.utils.StatusCode.DO_NOT_REPEAT;
import static com.houger.ddd.common.utils.StatusCode.NOT_IN_RUN;


/**
 * @author Houger.
 * @date 2024年05月27日 14:26.
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
@ActivityTemplateConfig(
    name = "秒杀",
    bizExtData = SeckillBizExtDataDto.class,
    instanceExtData = SeckillInstanceExtDataDto.class,
    rewardItemExtData = SeckillRewardItemExtDataDto.class,
    uiExtData = SeckillUiExtDataDto.class
)
public class SecKillTemplate extends ActivityTemplate  {



    @Override
    protected void updateInstanceStatus(final int status) {

    }

    @Override
    public void setBeanHolder(final BeanHolder beanHolder) {
        this.beanHolder=beanHolder;
    }

    public void checkRestrict(final Long instanceId, final Long userId) {
        final ActivityInstanceDto instanceDto = this.queryActivityInstanceContext(instanceId).getInstanceDto();
        final Integer playerMaxLimit = instanceDto.getPlayerMaxLimit();
        if (playerMaxLimit>0){
            throw new BusinessException(StatusCode.LIMITED);
        }
    }
}
